Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

detect-browser

Package Overview
Dependencies
Maintainers
3
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

detect-browser

Unpack a browser type and version from the useragent string

  • 4.8.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
991K
increased by1.28%
Maintainers
3
Weekly downloads
 
Created

What is detect-browser?

The detect-browser npm package is used to determine information about the browser or node version that the code is running in. It can detect the browser name, version, and operating system. This is particularly useful for client-side scripting where you might need to tailor behavior or workarounds for specific browsers or versions.

What are detect-browser's main functionalities?

Detecting browser information

This feature allows you to detect the browser name, version, and operating system. The `detect` function returns an object with this information if it's able to determine it, otherwise it returns `null`.

const { detect } = require('detect-browser');
const browser = detect();
if (browser) {
  console.log(browser.name);
  console.log(browser.version);
  console.log(browser.os);
}

Detecting node information

This feature is used to detect if the code is running in Node.js and to determine the Node.js version. The `detect` function returns an object with the version if the environment is Node.js.

const { detect } = require('detect-browser');
const browser = detect();
if (browser && browser.type === 'node') {
  console.log(browser.version);
}

Bot detection

This feature allows you to detect if the user-agent is a bot. The `detect` function returns an object with a `bot` property set to `true` if a bot is detected.

const { detect } = require('detect-browser');
const browser = detect();
if (browser && browser.bot) {
  // Handle bot-specific logic
}

Other packages similar to detect-browser

Keywords

FAQs

Package last updated on 26 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc